<?php
/**
 * Created by PhpStorm.
 * User: hotpot
 * Date: 2018/4/8
 * Time: 0:11
 */

namespace Admin\Controller;


use Common\Controller\AdminBaseController;

class ZiyuanController extends AdminBaseController
{
    // 定义数据
    private $db;

    public function __construct(){
        parent::__construct();
        $this->db=D('Ziyuan');
    }

    // 列表
    public function index(){
//        $data=$this->db->getDataByState(0,'all');

        $data = M('Ziyuan  as  a')
            ->join('bjy_zykind  as  b  on b.kind_id = a.ziyuan_kind')
            ->where("a.is_delete=0 and a.is_show=1")
            ->select();
        $this->assign('data',$data);
        $this->display();
    }

    // 添加
    public function add(){
        if(IS_POST){
            if($this->db->addData()){
                $this->success('资源添加成功',U('Admin/Ziyuan/index'));
            }else{
                $this->error($this->db->getError());
            }
        }else{
            $map=array(
                'is_delete'=>0
            );
            $kind=D("Zykind")->where($map)->select();
            $this->assign('kind',$kind);
            $this->display();
        }

    }

    // 修改
    public function edit(){
        if(IS_POST){
            if($this->db->editData()){
                $this->success('修改成功',U('Admin/Ziyuan/index'));
            }else{
                $this->error($this->db->getError());
            }
        }else{
            $map=array(
                'is_delete'=>0
            );
            $kind=D("Zykind")->where($map)->select();
            $this->assign('kind',$kind);
            $ziyuan_id=I('get.ziyuan_id');
            $data=$this->db->getDataByLid($ziyuan_id);
            $this->assign('data',$data);
            $this->display();
        }
    }

}